"use strict";
/* Controllers */
app.controller("xinghuoReportListController", ['$scope', '$location', '$rootScope', '$routeParams', 'xinghuoReportListService', function ($scope, $location, $rootScope, $routeParams, xinghuoReportListService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.dashboardType = 'report';
    vm.result = {};
    //vm.p.appID = $routeParams.appID; //  获取应用模块的名称

    //datetimePicker('datetimepicker','myDate');
    //if($rootScope.ds==null) {
    //    vm.ds = getDateStr(-1);
    //    $rootScope.ds = getDateStr(-1);
    //}else {
    //    vm.ds = $rootScope.ds;
    //}

    //vm.dim = 'week';
    //vm.dims = {};
    //vm.dims.items = [{idx:0,label:'日账单',id:'day'},{idx:1,label:'周账单',id:'week'}];
    //
    //if($rootScope.dim==null) {
    //    vm.dim = vm.dims.items[0];
    //    $rootScope.dim = vm.dim;
    //}else {
    //    vm.dim = vm.dims.items[$rootScope.dim.idx];
    //}
    //
    //$scope.vm.onDimSelected = function(id) {
    //    $scope.initializeController();
    //    $rootScope.dim = $scope.vm.dim;
    //};

    var errorFn = function (result) {
        alert(result);
    };

    $scope.listXinghuoReport = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        var params = { dashboardType: vm.p.dashboardType};
        var procFn = function (response) {
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) return;
            vm.result.data = data;
            $('#list_table').bootstrapTable('load', data);
        };
        xinghuoReportListService.listXinghuoReport(params, procFn, errorFn);
    };

    $scope.initializeController = function () {
        vm.result.ms = '';
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
        $scope.listXinghuoReport();
    };

    $scope.initializeController();

}]);


/* Services */
app.service('xinghuoReportListService', ['ajaxService', function (ajaxService) {

    this.listXinghuoReport = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/dashboard/loadDashboard.do", successFunction, errorFunction);
    };
}]);

function xinghuoReportIDOptFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a href="#/star/report/xinghuo_report_add/', value,'" target="_blank">', "<u>修改</u>" , '</a>'
    ].join('');
}
